package ejb.facades.forum;

import ejb.facades.AbstractFacade;
import entities.forum.Post;
import entities.forum.Topic;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 * Trabalho PD - 2014/2015
 * @author a21210380 a21210392
 */
@Stateless
public class PostFacade extends AbstractFacade<Post> implements PostFacadeLocal {
    @PersistenceContext(unitName = "Trabalho_PDPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public PostFacade() {
        super(Post.class);
    }
    
    @Override
    public List<Post> getPostsFromTopic(Topic topic) {
        return em.createNamedQuery("Post.findByIdTopic", Post.class)
                .setParameter("idTopic", topic)
                .getResultList();
    }
}
